/**
  * 终止合作
 */

<template lang='pug'>
  Modal(v-model="show" title="终止合作" :closable="false" :mask-closable="false")
    Form(ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="125")
      FormItem(label="终止合作原因：" prop="stopCooperateReason")
        Input.input-has-border(v-model="formValidate.stopCooperateReason" type="textarea" style="width:100%" clearable)
    template(slot="footer")
      Button(@click="cancel") 取消
      Button(type="info" :loading="loading" @click="handleSubmit('formValidate')") 确定
</template>

<script>
import dataApi from '@/api/data.js'

export default {
  name: "StopCooperate",
  props: {
    show: false,
    handleId: String
  },
  data() {
    return {
      loading: false,
      formValidate: {
        stopCooperateReason: '' // 终止原因
      },
      ruleValidate: {
        stopCooperateReason: [
          { required: true, message: '请填写终止原因', trigger: 'blur' }
        ]
      }
    }
  },

  computed: {},

  mounted() {},

  methods: {
    cancel () {
      this.$emit('on-cancel')
    },
    
    handleSubmit (name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          dataApi.postTerminateContract({
            CustomerIds: this.handleId,
            Reason: this.formValidate.stopCooperateReason
          }).then((res) => {
            this.loading = false
            if (res.data.success) {
              this.$Message.success('操作成功！')
              this.$refs['formValidate'].resetFields();
              this.$emit('get-list')
            } else {
              this.$Message.error({
                content: res.data.message,
                duration: 10,
                closable: true
              })
            }
          })
        } else {
        }
      })
    }
  },

  watch: {

  }
};
</script>
<style lang='less' scoped>
.d-f-c{
  display: flex;
  align-items: flex-start;
  span{
    display: inline-block;
    width: 125px;
    padding-right: 12px;
  }
  .content{
    flex: 1;
  }
}
</style>